//
//  BCProtocolController.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/12/18.
//  Copyright © 2018 guoshikeji. All rights reserved.
//

#import "BCProtocolController.h"

@interface BCProtocolController ()

@property (nonatomic, strong) UIViewController *prentingController;

@end

@implementation BCProtocolController

+ (void)showFromController:(UIViewController *)controller protocolURLString:(NSString *)protocolURLString {
    if (controller&&protocolURLString) {
        BCProtocolController *vc = [BCProtocolController new];
        vc.protocolURLString = protocolURLString;
        vc.prentingController = controller;
        [controller presentViewController:vc animated:true completion:nil];
    }
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleDefault;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //
    [self.customNaviBar.leftButton setImage:nil forState:UIControlStateNormal];
//    [self.customNaviBar.rightButton setImage:LOAD_IMAGE(@"general_close") forState:UIControlStateNormal];
//    self.customNaviBar.rightButton.imageEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 10);
//    [self.customNaviBar layoutSubviews];
    self.customNaviBar.rightButton.alpha = 1;
    
    //
    [self loadRequestWithURL:[NSURL URLWithString:self.protocolURLString]];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}



#pragma mark - override
// 当main frame导航完成时，会回调
- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation {
    [super webView:webView didFinishNavigation:navigation];
    //
    self.customNaviBar.rightButton.alpha = 1;
}

- (void)didClickedNaviRightButton {
    if (self.navigationController) {
        if (self.navigationController.viewControllers.count == 1) {
            [self.navigationController dismissViewControllerAnimated:YES completion:nil];
        }else {
            [self.navigationController popViewControllerAnimated:YES];
        }
    }else {
        [self dismissViewControllerAnimated:true completion:nil];
    }
}

@end
